package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysPayment;
import com.ruoyi.system.service.ISysPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/api/payment")
public class SysPaymentController extends BaseController
{
    @Autowired
    private ISysPaymentService sysPaymentService;

    /**
     * 查询【支付】列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(SysPayment sysPayment)
    {
        startPage();
        List<SysPayment> list = sysPaymentService.selectSysPaymentList(sysPayment);
        return getDataTable(list);
    }

    /**
     * 导出【支付】列表
     */
    @PreAuthorize("@ss.hasPermi('api:payment:export')")
    @Log(title = "【支付】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPayment sysPayment)
    {
        List<SysPayment> list = sysPaymentService.selectSysPaymentList(sysPayment);
        ExcelUtil<SysPayment> util = new ExcelUtil<SysPayment>(SysPayment.class);
        util.exportExcel(response, list, "【支付】数据");
    }

    /**
     * 获取【支付】详细信息
     */
    @Anonymous
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") String paymentId)
    {
        return success(sysPaymentService.selectSysPaymentByPaymentId(paymentId));
    }

    /**
     * 新增【支付】
     */
    @Anonymous
    @Log(title = "【支付】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPayment sysPayment)
    {
        return toAjax(sysPaymentService.insertSysPayment(sysPayment));
    }

    /**
     * 修改【支付】
     */
    @Anonymous
    @Log(title = "【支付】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPayment sysPayment)
    {
        return toAjax(sysPaymentService.updateSysPayment(sysPayment));
    }

    /**
     * 删除【支付】
     */
    @PreAuthorize("@ss.hasPermi('api:payment:remove')")
    @Log(title = "【支付】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable String[] paymentIds)
    {
        return toAjax(sysPaymentService.deleteSysPaymentByPaymentIds(paymentIds));
    }
}
